import tkinter as tk
# 导入NTPClient类·获取精准的东八区时间
from get_ntplib_nowtime import NTPClient
# 导入时辰显示
from GetShiChen import GetShiChen
# 导入webAPI
from webApi_info_long import WebApi
# 导入数据
from GetMySQL import MySQLDB
# 线程处理
from threading import Thread
import time
from tkinter import messagebox
# 解决跨类包打包引入问题
import pymysql

# 全局变量
# 信息集合
global hour_info
# 关闭线程
is_stop = True


def center_window(window):
    """
    将窗口居中显示
    """
    window.update_idletasks()  # 更新窗口的空闲任务，以确保窗口的尺寸已经被计算
    width = window.winfo_width()  # 获取窗口的宽度
    height = window.winfo_height()  # 获取窗口的高度
    x = (window.winfo_screenwidth() // 2) - (width // 2) - 20  # 计算窗口左边缘的x坐标
    y = (window.winfo_screenheight() // 2) - (height // 2)  # 计算窗口上边缘的y坐标
    window.geometry(f'+{x}+{y}')  # 设置窗口的位置


# 创建一个Tk根窗口实例
root = tk.Tk()

# 设置窗体的大小
root.geometry("800x600")

# 调用函数将窗口居中
center_window(root)

# 取消窗口的大小可变性
root.resizable(False, False)
# 窗体设置标题
root.title("AI易经出行")

# 绘制主界面框架

# 背景色-太师青-稳重
main_frame = tk.Frame(root, bg='#527486')
main_frame.pack(fill=tk.BOTH, expand=True)  # 使Frame填充整个窗体

# 分隔-云门色-祥云福佑-鼎运
canvas = tk.Canvas(root, width=700, height=10, bg="#9AC9D9", highlightthickness=0)
canvas.place(x=50, y=20)

# 九宫格-碧城色-优雅与沉静
for i in range(3):
    for j in range(3):
        x1 = 50 + i * 235
        y1 = 40 + j * 115
        x2 = x1 + 235
        y2 = y1 + 115
        canvas = tk.Canvas(root, width=230, height=110, bg="#0D4E77", highlightthickness=0)
        canvas.pack()
        canvas.place(x=x1, y=y1)

# 分隔-云门色-祥云福佑-中福
canvas = tk.Canvas(root, width=700, height=10, bg="#9AC9D9", highlightthickness=0)
canvas.place(x=50, y=390)

# 功能栏-提夫尼蓝-尊贵
for i in range(3):
    x1 = 50 + i * 235
    y1 = 410
    x2 = x1 + 235
    y2 = y1 + 50
    canvas = tk.Canvas(root, width=230, height=150, bg="#418683", highlightthickness=0)
    canvas.pack()
    canvas.place(x=x1, y=y1)

# 分隔-云门色-祥云福佑-底蕴
canvas = tk.Canvas(root, width=700, height=10, bg="#9AC9D9", highlightthickness=0)
canvas.place(x=50, y=570)


# 主页面——非必要信息
def show_message():
    """
    主页面——非必要文字信息——可控制是否显示
    :return:
    """
    main_label_t = tk.Label(root, text="抬头见喜", font=('宋体', 9), fg='#FFFFCC', bg='#527486', compound='left')
    main_label_t.place(x=380, y=0)

    main_label_b = tk.Label(root, text="低头遇福", font=('宋体', 9), fg='#FFFFCC', bg='#527486', compound='left')
    main_label_b.place(x=380, y=580)


# 显示主页面——非必要信息
show_message()

# 所有文字列表
top_label = tk.StringVar()
top_label.set("祥云福佑-鼎运")
# 创建一个StringVar对象，用于存储当前时间以及更新当前时间
NTPC_time = tk.StringVar()

# 创建一个Label对象，用于显示当前时间
main_label_NTPC_time = tk.Label(root, text=str(NTPC_time), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77',
                                compound='left',
                                textvariable=NTPC_time)
main_label_NTPC_time.place(x=300, y=160)
# 用于显示农历时间
n_lunar = tk.StringVar()
main_label_n_lunar = tk.Label(root, text=str(n_lunar), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77',
                              compound='left',
                              textvariable=n_lunar)
main_label_n_lunar.place(x=288, y=195)
# 是否是吉日
n_ji = tk.StringVar()
main_label_n_ji = tk.Label(root, text=str(n_ji), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77',
                           compound='left',
                           textvariable=n_ji)
main_label_n_ji.place(x=468, y=195)
# 用户显示农历时刻
n_shi_chen = tk.StringVar()
main_label_n_shi_chen = tk.Label(root, text=str(n_shi_chen), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77',
                                 compound='left',
                                 textvariable=n_shi_chen)
main_label_n_shi_chen.place(x=340, y=230)
# 八个方向文字
n = tk.StringVar()  # 北
main_label_n = tk.Label(root, text="北", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_n.place(x=390, y=40)
main_label_n_v = tk.Label(root, text=str(n), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                          textvariable=n)
main_label_n_v.place(x=375, y=70)
n_v_info = tk.StringVar()
main_label_n_v_info = tk.Label(root, text=str(n_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                               wraplength=150, justify='left',
                               compound='center',
                               textvariable=n_v_info)
main_label_n_v_info.place(x=335, y=100)

s = tk.StringVar()  # 南
main_label_s = tk.Label(root, text="南", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_s.place(x=390, y=350)
main_label_s_v = tk.Label(root, text=str(s), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                          textvariable=s)
main_label_s_v.place(x=375, y=290)
s_v_info = tk.StringVar()
main_label_s_v_info = tk.Label(root, text=str(s_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                               wraplength=150, justify='left',
                               compound='center',
                               textvariable=s_v_info)
main_label_s_v_info.place(x=335, y=320)

w = tk.StringVar()  # 西
main_label_w = tk.Label(root, text="西", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_w.place(x=50, y=200)
main_label_w_v = tk.Label(root, text=str(w), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                          textvariable=w)
main_label_w_v.place(x=140, y=180)
w_v_info = tk.StringVar()
main_label_w_v_info = tk.Label(root, text=str(w_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                               wraplength=150, justify='left',
                               compound='center',
                               textvariable=w_v_info)
main_label_w_v_info.place(x=90, y=210)

e = tk.StringVar()  # 东
main_label_e = tk.Label(root, text="东", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_e.place(x=720, y=200)
main_label_e_v = tk.Label(root, text=str(e), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                          textvariable=e)
main_label_e_v.place(x=610, y=180)
e_v_info = tk.StringVar()
main_label_e_v_info = tk.Label(root, text=str(e_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                               wraplength=150, justify='left',
                               compound='center',
                               textvariable=e_v_info)
main_label_e_v_info.place(x=560, y=210)

wn = tk.StringVar()  # 西北
main_label_wn = tk.Label(root, text="西北", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_wn.place(x=50, y=40)
main_label_wn_v = tk.Label(root, text=str(wn), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                           textvariable=wn)
main_label_wn_v.place(x=140, y=70)
wn_v_info = tk.StringVar()
main_label_wn_v_info = tk.Label(root, text=str(wn_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                                wraplength=150, justify='left',
                                compound='center',
                                textvariable=wn_v_info)
main_label_wn_v_info.place(x=90, y=100)

en = tk.StringVar()  # 东北
main_label_en = tk.Label(root, text="东北", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_en.place(x=700, y=40)
main_label_en_v = tk.Label(root, text=str(en), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                           textvariable=en)
main_label_en_v.place(x=610, y=70)
en_v_info = tk.StringVar()
main_label_en_v_info = tk.Label(root, text=str(en_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                                wraplength=150, justify='left',
                                compound='center',
                                textvariable=en_v_info)
main_label_en_v_info.place(x=560, y=100)

ws = tk.StringVar()  # 西南
main_label_ws = tk.Label(root, text="西南", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_ws.place(x=50, y=350)
main_label_ws_v = tk.Label(root, text=str(ws), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                           textvariable=ws)
main_label_ws_v.place(x=140, y=290)
ws_v_info = tk.StringVar()
main_label_ws_v_info = tk.Label(root, text=str(ws_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                                wraplength=150, justify='left',
                                compound='center',
                                textvariable=ws_v_info)
main_label_ws_v_info.place(x=90, y=320)

es = tk.StringVar()  # 东南
main_label_es = tk.Label(root, text="东南", font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_label_es.place(x=700, y=350)
main_label_es_v = tk.Label(root, text=str(es), font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77', compound='center',
                           textvariable=es)
main_label_es_v.place(x=610, y=290)
es_v_info = tk.StringVar()
main_label_es_v_info = tk.Label(root, text=str(es_v_info), font=('宋体', 11), fg='#FFFFCC', bg='#0D4E77',
                                wraplength=150, justify='left',
                                compound='center',
                                textvariable=es_v_info)
main_label_es_v_info.place(x=560, y=320)


# 创建一个线程，用于每隔一段时间更新时间
def update_time():
    """
    ISO 8601格式的时间处理·用于更新时间·出现异常的次数较多。
    :return:
    """
    start_time = NTPClient().get_time().strftime("%Y-%m-%d %H:%M:%S")
    while is_stop:
        # 根据start_time起始时间，不再访问其它函数，每次自增1秒来修改NTPC_time的时间
        try:
            start_time = NTPClient.increment_time_string(start_time, 1)
            NTPC_time.set(start_time)
            time.sleep(1)
        except Exception as e1:
            print("时间:", e1)


thread_update_time = Thread(target=update_time)
thread_update_time.start()


def get_hour_info(y, m, d, h):
    """
    获取指定日期和小时的信息
    :param y:
    :param m:
    :param d:
    :param h:
    :return:
    """
    result = MySQLDB.get_one_data(y, m, d)
    for ij in result:
        for j1 in range(0, 113):
            if int(ij[21][11:13]) == int(h):
                global hour_info
                hour_info = ij
                return ij


def start_ai_now():
    """
    开始AI计算逻辑·计算当前时刻分析
    """
    thread_ai_calculate = Thread(target=get_webapi_or_mysql)
    thread_ai_calculate.start()


# 刷新数据
tk_button_now_luck = tk.Button(root, text="(刷新)", font=('宋体', 10), fg='#FFFFCC', command=start_ai_now,
                               bg="#0D4E77")
tk_button_now_luck.place(x=450, y=235)

# 问题详情变量
question_info = tk.StringVar()


def ai_calculate():
    """
    AI计算
    :return:
    """
    ai_button.configure(text="AI分析中...", state='disabled')
    tk_button_now_luck.configure(state='disabled')
    print("AI计算中...")
    info_s = WebApi.get_info_s(hour_info, n_shi_chen.get(), main_entry_user_birthday.get())
    # 直接给问题赋值
    question_info.set(info_s)
    # 访问AI获取结果
    result = WebApi.content_info(info_s)
    # 北
    n.set(result['n'][0])
    if str(result['n'][0]).find("吉") != -1:
        main_label_n_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_n_v.configure(fg='black')
    n_v_info.set(result['n'][1])
    # 南
    s.set(result['s'][0])
    if str(result['s'][0]).find("吉") != -1:
        main_label_s_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_s_v.configure(fg='black')
    s_v_info.set(result['s'][1])
    # 西
    w.set(result['w'][0])
    if str(result['w'][0]).find("吉") != -1:
        main_label_w_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_w_v.configure(fg='black')
    w_v_info.set(result['w'][1])
    # 东
    e.set(result['e'][0])
    if str(result['e'][0]).find("吉") != -1:
        main_label_e_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_e_v.configure(fg='black')
    e_v_info.set(result['e'][1])
    # 西北
    wn.set(result['nw'][0])
    if str(result['nw'][0]).find("吉") != -1:
        main_label_wn_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_wn_v.configure(fg='black')
    wn_v_info.set(result['nw'][1])
    # 东北
    en.set(result['ne'][0])
    if str(result['ne'][0]).find("吉") != -1:
        main_label_en_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_en_v.configure(fg='black')
    en_v_info.set(result['ne'][1])
    # 西南
    ws.set(result['sw'][0])
    if str(result['sw'][0]).find("吉") != -1:
        main_label_ws_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_ws_v.configure(fg='black')
    ws_v_info.set(result['sw'][1])
    # 东南
    es.set(result['se'][0])
    if str(result['se'][0]).find("吉") != -1:
        main_label_es_v.configure(fg='#FFD700')
    elif str(result['n'][0]) == "正交":
        main_label_n_v.configure(fg='red')
    else:
        main_label_es_v.configure(fg='black')
    es_v_info.set(result['se'][1])
    """
        {"n":["XX","XXXX,XXXX."],
        "ne":["XX","XXXX,XXXX."],
        "e":["XX","XXXX,XXXX."],
        "se":["XX","XXXX,XXXX."],
        "s":["XX","XXXX,XXXX."],
        "sw":["XX","XXXX,XXXX."],
        "w":["XX","XXXX,XXXX."],
        "nw":["XX","XXXX,XXXX."]}
    """
    print("AI计算完成。")
    ai_button.configure(text="提交AI生活分析", state='normal')
    tk_button_now_luck.configure(state='normal')


# 判断输入的日期是否合法
def validate_date():
    # main_entry_user_birthday.get()的长度必须大于4个字符
    if len(main_entry_user_birthday.get()) <= 4:
        messagebox.showerror("错误", "请输入大于2个中文长度的问题。")
        return
    thread_ba_zi_ai_calculate = Thread(target=get_ai_zhou_yi_def)
    thread_ba_zi_ai_calculate.start()


def get_ai_zhou_yi_def():
    # 修改ai_button状态为不可用
    ai_button.configure(text="AI分析中...", state='disabled')
    print("开始AI易经生活万事通计算。。。")
    result = WebApi.get_ai_zhou_yi(main_entry_user_birthday.get())
    print("完成开始AI易经生活万事通计算。")
    # 绘制到右侧窗口
    main_button_wide.config(text="收回")
    main_text_question.configure(font=('宋体', 12), width=20, height=50)
    main_text_question.delete(1.0, tk.END)
    main_text_question.insert(tk.INSERT, result)
    root.geometry("1040x600")
    ai_button.configure(text="提交AI生活分析", state='normal')


# AI易经问题解答
def ai_yijing_question():
    """
    启动 AI易经问题解答
    :return:
    """
    thread_ai_calculate = Thread(target=get_ai_zhou_yi_def)
    thread_ai_calculate.start()


# 用户出生年月日提示文字
main_label_user_birthday = tk.Label(root, text="AI易经生活万事通：", font=('宋体', 15), fg='#FFFFCC', bg='#418683')
main_label_user_birthday.place(x=55, y=420)
# 用户自定义生活中的易经问题输入组件
main_entry_user_birthday = tk.Entry(root, width=22, font=('宋体', 15), fg='#FFFFCC', bg='#0D4E77')
main_entry_user_birthday.insert(0, '例如：巽卦挂义')
main_entry_user_birthday.place(x=53, y=460)
# AI分析按钮
# ai_button = tk.Button(root, text="AI分析中...", width=29, command=validate_date)
ai_button = tk.Button(root, text="AI分析中...", width=29, command=validate_date, state='disabled')
ai_button.place(x=58, y=500)

# 显示方位信息
main_label_ji = tk.Label(root, text="当前时刻出行分析", font=('宋体', 15), fg='#FFFFCC', bg='#418683')
main_label_ji.place(x=310, y=420)


def get_day_one_gua():
    gua = WebApi.get_day_one_gua()
    main_text_button_g.delete(1.0, tk.END)
    main_text_button_g.insert(tk.INSERT, gua)


def start_gua():
    thread_gua = Thread(target=get_day_one_gua)
    thread_gua.start()


main_button_g = tk.Button(root, text="起卦-每日一挂", font=('宋体', 15), command=start_gua, fg='#FFFFCC', bg='#418683')
main_button_g.place(x=560, y=415)

main_text_button_g = tk.Text(root, width=29, height=8, font=('宋体', 10), fg='#FFFFCC', bg='#418683', borderwidth=0)
main_text_button_g.place(x=535, y=450)


def get_webapi_or_mysql():
    """初始化函数"""
    # 初始时间，为防止本地时间异常,则使用NTP获取时间数据
    while True:
        try:
            show_time = NTPClient().get_time().strftime("%Y-%m-%dT%H:%M:%S")
            break
        except Exception as e1:
            print("时间:", e1)
    year = str(show_time)[0:4]  # 年
    month = str(show_time)[5:7]  # 月
    day = str(show_time)[8:10]  # 日
    hour = str(show_time)[11:13]  # 时
    fen = str(show_time)[14:16]  # 分
    result = get_hour_info(year, month, day, hour)  # 获取指定日期和小时的信息
    # 处理返回结果
    # 显示农历时间
    n_lunar.set(result[22])
    if result[112] == "吉":
        main_label_n_ji.configure(fg='#FFD700')
        n_ji.set("(吉)")
    else:
        main_label_n_ji.configure(fg='black')
        n_ji.set("(凶)")
    # 显示农历时刻
    n_shi_chen.set(GetShiChen.get_shi_chen(int(hour), int(fen)))
    # 显示八方
    n.set("推演中...")
    s.set("推演中...")
    w.set("推演中...")
    e.set("推演中...")
    wn.set("推演中...")
    en.set("推演中...")
    ws.set("推演中...")
    es.set("推演中...")
    # 启动ai_calculate
    thread_ai_calculate = Thread(target=ai_calculate)
    thread_ai_calculate.start()
    # 启动ai_calculate_now
    thread_ai_calculate_now = Thread(target=ai_calculate_now)
    thread_ai_calculate_now.start()


# 启动线程，获取webapi数据或MySQL数据，并进行处理
thread_get_webapi = Thread(target=get_webapi_or_mysql)
thread_get_webapi.start()


def ai_calculate_now():
    """
    执行AI计算逻辑·计算当前时刻分析
    """
    main_now.configure(state='normal')
    main_now.delete('1.0', tk.END)
    main_now.insert(tk.INSERT, WebApi.get_ai_info())
    main_now.configure(state='disabled')


# 当前时刻分析文本
main_now = tk.Text(root, width=29, height=8, font=('宋体', 10), fg='#FFFFCC', bg='#418683', borderwidth=0)
main_now.place(x=300, y=450)


def on_closing():
    """
    关闭窗口时触发的事件
    :return:
    """
    if tk.messagebox.askokcancel("退出", "您确定要退出吗？"):
        global is_stop
        is_stop = False
        root.destroy()
    exit(0)


# 设置问题显示Text
main_text_question = tk.Text(root, width=35, height=78, font=('宋体', 9), fg='#FFFFCC', bg='#527486', borderwidth=0)
main_text_question.place(x=805, y=20)


# 增宽函数
def wide_window():
    # 判断增宽窗体按钮的文字是否为"增宽窗体"
    if main_button_wide["text"] == "详情":
        main_text_question.delete(1.0, tk.END)
        main_text_question.insert(tk.INSERT, question_info.get())
        root.geometry("1040x600")
        main_button_wide.config(text="收回")
    else:
        main_text_question.delete(1.0, tk.END)
        root.geometry("800x600")
        main_button_wide.config(text="详情")


def n_i(type_n):
    main_button_wide.config(text="收回")
    main_text_question.configure(font=('宋体', 15), width=20, height=50)
    main_text_question.delete(1.0, tk.END)
    if type_n == "n":
        info_if = """北方坎卦位:
        
吉：
    坎位代表中男，属水，被称为 “财山”，主智慧和发展。北方方位高，利于学业和财运，有 “家宅靠山” 之说，能提升家宅的长久运势。
--------------------
凶：
    该方位风水不好时，会导致破财、贫穷、不易生育、奔波劳碌等状况。在健康方面，易引发下腹病、泌尿系统病、生殖系统病、免疫系统病、拉肚子、水肿病、腰脊病、性病、遗精等疾病；在灾祸方面，可能出现溺水、耳聋、服毒自杀、被水烫伤、酒精中毒、食物药物中毒等意外。
"""
    elif type_n == "s":
        info_if = """南方离卦位:
        
吉：
    离位代表中女，属火，是正财之位、文昌之地。南方见水吉，见砂凶。该方位风水好时，主财富、前途、事业、荣誉，对个人的财运和事业发展有利。
--------------------
凶：
    若南方风水不好，会导致失财、贫穷、困苦等情况。在健康方面，易引发心脑血管病、放射性疾病、扩散性疾病、妇科病、血液病、眼目病等疾病；在灾祸方面，可能出现心脏被刺伤、眼睛被损伤、烧伤、瞎眼等意外。
"""
    elif type_n == "w":
        info_if = """西方兑卦位:
        
吉：
    兑位代表少女，属金。此方位见水吉，为砂凶。风水好时，主艺术、歌舞、口才、横财，对个人的艺术才华和财运有帮助。
--------------------
凶：
    若西方风水不好，会出现失财、官司、口舌是非、兄弟不和、夫妻争吵等情况。在健康方面，可能引发口齿舌咽喉肺病、气管病、皮肤病、性病、咳嗽、食欲不佳、血压低、贫血等疾病；在灾祸方面，可能出现伤亡、流血、手术、外伤（刀伤、枪伤、车祸、撞伤、跌伤、打伤、扭伤、摔伤等意外事故）、缺唇、露齿等意外。
    """
    elif type_n == "e":
        info_if = """东方震卦位:
        
吉：
    震位代表长男，属木。东方见砂（阳性的物体）则贵，见水则贱。震方全体砂，可助家庭文武共兴，带来官贵（武官）、福禄、发血光之财等好运。
--------------------
凶：
    若东方风水不好，会导致贫穷、困苦、淫乱等情况。在健康方面，易引发精神神经衰弱、妇科病、突发性疾病、咳嗽、声带咽喉病、肝病、腿脚病瘫痪等疾病；在灾祸方面，可能出现跛足、小儿麻痹、手脚伤残、被硬木损伤等意外。
"""
    elif type_n == "nw":
        info_if = """西北乾卦位:
        
吉：
    此方位为寿卦位，代表家中父辈，五行属金，主贵气、旺气、寿运。若该方位风水好，可带来官贵（文官）、首领地位、文昌运、威严、仁德等，对提升个人的名声、地位、学业和领导能力有帮助。
--------------------
凶：
    如果乾位风水不佳，会出现贫贱、愚笨、死亡、傲慢、霸道等情况。在健康方面，可能引发头部病、肺病、骨病、陈旧性损伤、硬化性病和瘫痪等疾病；在运势上，可能导致失财、降职、官非以及被金属撞伤等灾祸。
"""
    elif type_n == "ne":
        info_if = """东北艮卦位:
        
吉：
    艮位代表少男，属土，是胎元之地。此方位吉利时，主生育后代、人丁兴旺、发财、聪明。东北方风水好，对家庭的人丁和财运都有积极影响。
--------------------
凶：
    若风水不佳，会出现绝后损丁、破财、愚痴等情况。在健康方面，可能引发脾胃病、鼻病、手指病、脊背病、关节病、水肿病、营养不良、结石病、肿瘤病、皮肤病、血脉病、血脉腿、瘫痪等疾病。
"""
    elif type_n == "sw":
        info_if = """东南巽卦位:
        
吉：
    巽位代表长女，属木。此方位有砂则吉，有水则凶，但砂不能太高。巽位风水好时，主妇女持家、勤劳致富、发财、出文人、发女贵，对女性的运势有积极影响。
--------------------
凶：
    若风水不佳，会出现酗酒、风流、淫乱等情况。在健康方面，可能引发传染病、胆囊病、中风、瘫痪、秃头、感冒等疾病；在灾祸方面，可能有吊颈、蛇伤等危险。
"""
    else:
        info_if = """西南坤卦位:
        
吉：
    坤位代表老母，属土。西南有砂吉，见水凶。此方位风水好时，主发土石之财，女人健康能干、勤劳致富，生女秀丽、谦让、宽容、稳重。
--------------------
凶：
    若风水不佳，会出现淫乱、寡妇、小人、盗贼、吸毒、迟钝、卑贱、吝啬、小气等情况。在健康方面，可能引发腹部病、肌肉病、皮肤病、慢性病、肠胃消化疾病、气虚病、肿瘤病等疾病；在灾祸方面，可能出现失财、顽疾、死亡、被土石压伤等意外。
"""
    main_text_question.insert(tk.INSERT, info_if)
    root.geometry("1040x600")


# 增宽窗体按钮
main_button_wide = tk.Button(root, text="详情", font=('宋体', 12), command=wide_window, bg="#418683", fg='#FFFFCC')
main_button_wide.place(x=754, y=40)

main_label_n_i = tk.Label(root, text=" 北方 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                          borderwidth=1, relief='ridge')
main_label_n_i.place(x=754, y=80)
main_label_n_i.bind("<Button-1>", lambda event: n_i("n"))

main_label_s_i = tk.Label(root, text=" 南方 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                          borderwidth=1, relief='ridge')
main_label_s_i.place(x=754, y=120)
main_label_s_i.bind("<Button-1>", lambda event: n_i("s"))

main_label_w_i = tk.Label(root, text=" 西方 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                          borderwidth=1, relief='ridge')
main_label_w_i.place(x=754, y=160)
main_label_w_i.bind("<Button-1>", lambda event: n_i("w"))

main_label_e_i = tk.Label(root, text=" 东方 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                          borderwidth=1, relief='ridge')
main_label_e_i.place(x=754, y=200)
main_label_e_i.bind("<Button-1>", lambda event: n_i("e"))

main_label_nw_i = tk.Label(root, text=" 西北 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                           borderwidth=1, relief='ridge')
main_label_nw_i.place(x=754, y=240)
main_label_nw_i.bind("<Button-1>", lambda event: n_i("nw"))

main_label_ne_i = tk.Label(root, text=" 东北 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                           borderwidth=1, relief='ridge')
main_label_ne_i.place(x=754, y=280)
main_label_ne_i.bind("<Button-1>", lambda event: n_i("ne"))

main_label_sw_i = tk.Label(root, text=" 西南 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                           borderwidth=1, relief='ridge')
main_label_sw_i.place(x=754, y=320)
main_label_sw_i.bind("<Button-1>", lambda event: n_i("sw"))

main_label_se_i = tk.Label(root, text=" 东南 \n 吉凶 ", font=('Arial', 12), bg='#418683', cursor='hand2', fg='#FFFFCC',
                           borderwidth=1, relief='ridge')
main_label_se_i.place(x=754, y=360)
main_label_se_i.bind("<Button-1>", lambda event: n_i("se"))

# 拦截窗口关闭事件
root.protocol("WM_DELETE_WINDOW", on_closing)

# 启动事件循环
root.mainloop()
